package com.common.mq;

import com.alibaba.fastjson.JSON;
import com.system.entity.File;
import com.system.service.FileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MQReceiver {

    @Value("${file.path}")
    private String filePath;

    @Value("${file.base-url}")
    private String baseUrl;

    @Autowired
    private FileService fileService;

    @RabbitListener(queues=MQConfig.QUEUE)
    public void  receive(String json){
        FileMessage fileMessage = JSON.toJavaObject(JSON.parseObject(json), FileMessage.class);
        File file = fileMessage.getFile();
        this.fileService.save(file);
    }
}
